//part1:C16:ex16.4.cpp
// find value, from vector<int> and list<string>
#include <iostream>
#include <string>
#include <vector>
#include <list>
using namespace std;
template<typename I, typename T>
I find1(I b, I e, const T &v)
{
    while (b != e && *b != v) 
    {
        b++;
    }
    return b;
}

int main(void)
{
    vector<int> vi = {0, 2, 4, 6, 8, 10};
    list<string> ls= {"Hello", "World", "!"};

    auto iter = find1(vi.begin(), vi.end(), 6);
    if(iter == vi.end())
    {
        cout << "can not find 6" << endl;
    }
    else 
    {
        cout << "find 6 at position " << iter - vi.begin() << endl;
    }

    auto iter1 = find1(ls.begin(), ls.end(), "mom");
    if(iter1 == ls.end())
    {
        cout << "can not find mom" << endl;
    }
    else 
    {
        cout << "found mom" << endl;
    }
    return 0;
}